dofile ("libScreen.lua")

OS = {}

osx = 0
osy = 0

function OS.init ()
  OS.x = 0
  OS.y = 0
  OS.x2 = 256
  OS.y2 = 192
  
  OS.bx = 0
  OS.by = 0
  OS.bx2 = 256
  OS.by2 = 20
  
  OS.mx = OS.x
  OS.my = OS.y+20
  OS.mx2 = OS.x+100
  OS.my2 = OS.y2-20
  OS.mvisible = false
end

function OS.loadlib (lib)
  if lib ~= nil then
    dofile ("libs/"..lib..".lua")
  end
end

function OS.print (scr, x, y, text, color)
  if color == nil then color = c_blanc end
  screen.print (scr, x, OS.my+y, text, color)
end

function OS.drawTB (text)
  if Stylus.held then
    osx = Stylus.X
    osy = Stylus.Y
  end
  
  if text == nil or text == "" then text = "Menu" end
  local str = string.len (text)*6
  screen.drawGradientRect (SCREEN_DOWN, OS.bx, OS.by, OS.bx2, OS.by2, c_bleu, c_bleu, c_blanc, c_blanc)
  screen.print (SCREEN_DOWN, OS.x+7, OS.y+7, text, c_noir)
  
  OS.bm = newBox (OS.x, OS.y, OS.x+str+12, OS.y+20)
  
  if Stylus.newPressinBox (OS.bm, osx, osy) then
    OS.mvisible = not OS.mvisible
  end
end

function OS.drawMenu ()
  if OS.mvisible then
    screen.drawGradientRect (SCREEN_DOWN, OS.mx, OS.my, OS.mx2, OS.my2, c_bleu, c_blanc, c_bleu, c_blanc)
  end
end

function OS.printRAM (scr, x, y, color)
  if color == nil then color = c_blanc end
  screen.print (scr, x, y, tostring (gcinfo ()), color)
end

function OS.clear ()
  OS = nil
  
  osx = nil
  osy = nil
end

